from kivy.graphics import Color, Line
from kivy.uix.boxlayout import BoxLayout


# 自定义BoxLayout，当做表格的列
class ColLayout(BoxLayout):
    padding = [5, 5, 5, 5]

    def __init__(self, **kwargs):
        super(ColLayout, self).__init__(**kwargs)

        with self.canvas.before:
            # 设置边框
            Color(1, 0, 0, .9)  # Color(.3, .9, .3, .5)
            self.border = Line(rectangle=(self.x, self.y, self.width, self.height), width=1)
        self.bind(size=self.update_rect, pos=self.update_rect)

    def update_rect(self, instance, *args):
        # 更新边框
        self.border.rectangle = (self.x, self.y, self.width, self.height)
